import {GET_BRAND_LIST} from '../actionTypes';
const official = (state={brandList:{}},action) => {
    switch (action.type) {
        case GET_BRAND_LIST:{
            let {list} = action;

            /**
             * {
             *     A:[],
             *     B:[]
                    ...
             * }
             * 
             * 
            */

            let keys = [...new Set(list.map(item => item.Spelling.substr(0,1)))];
            // console.log(keys);

            let result = keys.reduce((prev,key) => {
                prev[key] = list.filter(item => item.Spelling.substr(0,1) === key);
                return prev
            },{})
            return {
               ...state,
               brandList:result
            }
        }
        default:{
            return state
        }
    }
}

export default official